/*
 * @(#)GenericService.java 2009-3-23
 * Copyright (c) 2008-2015 by CJK
 * All rights reserved.
 */
package net.beyond.common.ssh;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import net.jk.util.page.PaginationSupport;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.hibernate.criterion.DetachedCriteria;

/**
 * HibernateService实现,可通用作为每一个实体的baseService层。
 * 
 * @author Shmiluyu
 * @version 1.000 2009-3-23
 */
public class GenericService<T> implements HibernateService<T> {
	protected final Logger log = LogManager.getLogger(getClass());
	private HibernateRepository<T> dao;

	public GenericService() {
		super();
	}

	public HibernateRepository<T> getDao() {
		return dao;
	}

	public void setDao(HibernateRepository<T> dao) {
		this.dao = dao;
	}

	/*
	 * @see
	 * net.beyond.common.ssh.HibernateService#findAllByCriteria(org.hibernate
	 * .criterion.DetachedCriteria)
	 */
	public List<T> findAllByCriteria(DetachedCriteria detachedCriteria) {
		return dao.findAllByCriteria(detachedCriteria);
	}

	/*
	 * @see
	 * net.beyond.common.ssh.HibernateService#findPageByCriteria(org.hibernate
	 * .criterion.DetachedCriteria, int, int)
	 */
	public PaginationSupport<T> findPageByCriteria(
			DetachedCriteria detachedCriteria, int pageSize, int startIndex) {
		return dao.findPageByCriteria(detachedCriteria, pageSize, startIndex);
	}

	/*
	 * @see
	 * net.beyond.common.ssh.HibernateService#findPageByCriteria(org.hibernate
	 * .criterion.DetachedCriteria, int)
	 */
	public PaginationSupport<T> findPageByCriteria(
			DetachedCriteria detachedCriteria, int startIndex) {
		return dao.findPageByCriteria(detachedCriteria, startIndex);
	}

	/*
	 * @see
	 * net.beyond.common.ssh.HibernateService#findPageByCriteria(org.hibernate
	 * .criterion.DetachedCriteria)
	 */
	public PaginationSupport<T> findPageByCriteria(
			DetachedCriteria detachedCriteria) {
		return dao.findPageByCriteria(detachedCriteria);
	}

	/*
	 * @see
	 * net.beyond.common.ssh.HibernateService#getCountByCriteria(org.hibernate
	 * .criterion.DetachedCriteria)
	 */
	public int getCountByCriteria(DetachedCriteria detachedCriteria) {
		return dao.getCountByCriteria(detachedCriteria);
	}

	/*
	 * @see
	 * net.beyond.common.ssh.HibernateService#saveOrUpdate(java.lang.Object)
	 */
	public void saveOrUpdate(T newInstance) {
		dao.saveOrUpdate(newInstance);
	}

	/*
	 * @see net.beyond.common.ssh.Service#clearAll()
	 */
	public int clearAll() {
		return dao.clearAll();
	}

	/*
	 * @see net.beyond.common.ssh.Service#delete(java.lang.Object)
	 */
	public void delete(T persistentObject) {
		dao.delete(persistentObject);
	}

	/*
	 * @see net.beyond.common.ssh.Service#deleteAll(java.util.Collection)
	 */
	public void deleteAll(Collection<T> collections) {
		dao.deleteAll(collections);
	}

	/*
	 * @see net.beyond.common.ssh.Service#deleteById(java.io.Serializable)
	 */
	public void deleteById(String id) {
		dao.deleteById(id);
	}

	/*
	 * @see net.beyond.common.ssh.Service#deleteByIdSet(java.util.Set)
	 */
	public int deleteByIdSet(Set<String> idSet) {
		return dao.deleteByIdSet(idSet);
	}

	/*
	 * @see net.beyond.common.ssh.Service#get(java.io.Serializable)
	 */
	public T get(String id) {
		return dao.get(id);
	}

	/*
	 * @see net.beyond.common.ssh.Service#getAll()
	 */
	public List<T> getAll() {
		return dao.getAll();
	}

	/*
	 * @see net.beyond.common.ssh.Service#save(java.lang.Object)
	 */
	public T save(T newInstance) {
		return dao.save(newInstance);
	}

	/*
	 * @see net.beyond.common.ssh.Service#update(java.lang.Object)
	 */
	public void update(T transientObject) {
		dao.update(transientObject);
	}

}
